package com.wlys.player.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.ImageView;

import com.wlys.player.WlysApplication;
import com.wlys.player.utils.imagecache.ImageFetcher;
import com.wlys.player.utils.imagecache.ImageWorker;

public abstract class BaseCacheListAdapter<T> extends BaseListAdapter<T>
{

    protected LayoutInflater mInflater;
    protected ImageWorker mImageWorker;
    protected Context mContext;

    public BaseCacheListAdapter(Context context)
    {
        super();
        mContext = context;
        mInflater = LayoutInflater.from(context);
    }
    
    public void setCacheImage(final ImageView imageView, String imageUrl,
            final int resId)
    {
        if (mImageWorker == null)
        {
            // The ImageWorker takes care of loading images into our ImageView
            // children asynchronously
            mImageWorker = new ImageFetcher(mContext, WlysApplication.getLongest());
            mImageWorker.setImageCache(WlysApplication.getImageLruCache());
        }
        mImageWorker.setLoadingImage(resId);
        mImageWorker.loadImage(imageUrl, imageView);
    }

    /**
     * should be called when Activity is destoried
     * 
     * @Description:
     * @Author 12050514 wangwt
     * @Date 2012-8-17
     */
    public void destory()
    {
        super.clear();
        if (mImageWorker != null)
        {
            mImageWorker.setImageCache(null);
            mImageWorker = null;
        }
        mInflater = null;
    }

}
